/*
 * HRaplicationView.java
 */

package hraplication;

import com.mysql.jdbc.PreparedStatement;
import java.awt.Container;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.jdesktop.application.Application;

/**
 * The application's main frame.
 */
public class HRaplicationView extends FrameView {
    Konekcija kon;
    Boolean logovan;
    int idUposlenici;
    String pozicija;
    String username;
            
    public HRaplicationView(SingleFrameApplication app) {
        super(app);
        
        initComponents();
        kon = new Konekcija();
        kreirajPanele();

        LogOut();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = HRaplicationApp.getApplication().getMainFrame();
            aboutBox = new HRaplicationAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        HRaplicationApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPasswordField1 = new javax.swing.JPasswordField();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        MenuItemOdjava = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        organizacijaMenu = new javax.swing.JMenu();
        unosOrg = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        uposleniciMenu = new javax.swing.JMenu();
        unosUposlenikaMenuItem = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        vozilaMenu = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        unosServisaMenuItem = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        godisnjiMenu = new javax.swing.JMenu();
        zahtjevZaGOMenuItem = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        sluzbenaPutovanjaMenu = new javax.swing.JMenu();
        zahtjevZaSPMenuItem = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        kancMatMenu = new javax.swing.JMenu();
        zahtjevZaKancMatMenuItem = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        pregledMenu = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(hraplication.HRaplicationApp.class).getContext().getResourceMap(HRaplicationView.class);
        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("mainPanel.border.title"))); // NOI18N
        mainPanel.setName("mainPanel"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
        jPasswordField1.setName("jPasswordField1"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(48, 48, 48)))
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))))
                .addContainerGap(380, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(106, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        MenuItemOdjava.setText(resourceMap.getString("MenuItemOdjava.text")); // NOI18N
        MenuItemOdjava.setName("MenuItemOdjava"); // NOI18N
        MenuItemOdjava.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemOdjavaActionPerformed(evt);
            }
        });
        fileMenu.add(MenuItemOdjava);

        jSeparator2.setName("jSeparator2"); // NOI18N
        fileMenu.add(jSeparator2);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(hraplication.HRaplicationApp.class).getContext().getActionMap(HRaplicationView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        organizacijaMenu.setText(resourceMap.getString("organizacijaMenu.text")); // NOI18N
        organizacijaMenu.setName("organizacijaMenu"); // NOI18N

        unosOrg.setText(resourceMap.getString("unosOrg.text")); // NOI18N
        unosOrg.setName("unosOrg"); // NOI18N
        unosOrg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unosOrgActionPerformed(evt);
            }
        });
        organizacijaMenu.add(unosOrg);

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        organizacijaMenu.add(jMenuItem1);

        menuBar.add(organizacijaMenu);

        uposleniciMenu.setText(resourceMap.getString("uposleniciMenu.text")); // NOI18N
        uposleniciMenu.setName("uposleniciMenu"); // NOI18N

        unosUposlenikaMenuItem.setText(resourceMap.getString("unosUposlenikaMenuItem.text")); // NOI18N
        unosUposlenikaMenuItem.setName("unosUposlenikaMenuItem"); // NOI18N
        unosUposlenikaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unosUposlenikaMenuItemActionPerformed(evt);
            }
        });
        uposleniciMenu.add(unosUposlenikaMenuItem);

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        uposleniciMenu.add(jMenuItem2);

        menuBar.add(uposleniciMenu);

        vozilaMenu.setText(resourceMap.getString("vozilaMenu.text")); // NOI18N
        vozilaMenu.setName("vozilaMenu"); // NOI18N

        jMenuItem3.setText(resourceMap.getString("unosVozilaMenuItem.text")); // NOI18N
        jMenuItem3.setName("unosVozilaMenuItem"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        vozilaMenu.add(jMenuItem3);

        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        vozilaMenu.add(jMenuItem4);

        jSeparator1.setName("jSeparator1"); // NOI18N
        vozilaMenu.add(jSeparator1);

        unosServisaMenuItem.setText(resourceMap.getString("unosServisaMenuItem.text")); // NOI18N
        unosServisaMenuItem.setName("unosServisaMenuItem"); // NOI18N
        unosServisaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unosServisaMenuItemActionPerformed(evt);
            }
        });
        vozilaMenu.add(unosServisaMenuItem);

        jMenuItem5.setText(resourceMap.getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.setName("jMenuItem5"); // NOI18N
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        vozilaMenu.add(jMenuItem5);

        menuBar.add(vozilaMenu);

        godisnjiMenu.setText(resourceMap.getString("godisnjiMenu.text")); // NOI18N
        godisnjiMenu.setName("godisnjiMenu"); // NOI18N

        zahtjevZaGOMenuItem.setText(resourceMap.getString("zahtjevZaGOMenuItem.text")); // NOI18N
        zahtjevZaGOMenuItem.setName("zahtjevZaGOMenuItem"); // NOI18N
        zahtjevZaGOMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zahtjevZaGOMenuItemActionPerformed(evt);
            }
        });
        godisnjiMenu.add(zahtjevZaGOMenuItem);

        jMenuItem6.setText(resourceMap.getString("jMenuItem6.text")); // NOI18N
        jMenuItem6.setName("jMenuItem6"); // NOI18N
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        godisnjiMenu.add(jMenuItem6);

        menuBar.add(godisnjiMenu);

        sluzbenaPutovanjaMenu.setText(resourceMap.getString("sluzbenaPutovanjaMenu.text")); // NOI18N
        sluzbenaPutovanjaMenu.setName("sluzbenaPutovanjaMenu"); // NOI18N

        zahtjevZaSPMenuItem.setText(resourceMap.getString("zahtjevZaSPMenuItem.text")); // NOI18N
        zahtjevZaSPMenuItem.setName("zahtjevZaSPMenuItem"); // NOI18N
        zahtjevZaSPMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zahtjevZaSPMenuItemActionPerformed(evt);
            }
        });
        sluzbenaPutovanjaMenu.add(zahtjevZaSPMenuItem);

        jMenuItem7.setText(resourceMap.getString("jMenuItem7.text")); // NOI18N
        jMenuItem7.setName("jMenuItem7"); // NOI18N
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        sluzbenaPutovanjaMenu.add(jMenuItem7);

        menuBar.add(sluzbenaPutovanjaMenu);

        kancMatMenu.setText(resourceMap.getString("kancMatMenu.text")); // NOI18N
        kancMatMenu.setName("kancMatMenu"); // NOI18N

        zahtjevZaKancMatMenuItem.setText(resourceMap.getString("zahtjevZaKancMatMenuItem.text")); // NOI18N
        zahtjevZaKancMatMenuItem.setName("zahtjevZaKancMatMenuItem"); // NOI18N
        zahtjevZaKancMatMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zahtjevZaKancMatMenuItemActionPerformed(evt);
            }
        });
        kancMatMenu.add(zahtjevZaKancMatMenuItem);

        jMenuItem11.setText(resourceMap.getString("jMenuItem11.text")); // NOI18N
        jMenuItem11.setName("jMenuItem11"); // NOI18N
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        kancMatMenu.add(jMenuItem11);

        menuBar.add(kancMatMenu);

        pregledMenu.setText(resourceMap.getString("pregledMenu.text")); // NOI18N
        pregledMenu.setName("pregledMenu"); // NOI18N

        jMenuItem8.setText(resourceMap.getString("jMenuItem8.text")); // NOI18N
        jMenuItem8.setName("jMenuItem8"); // NOI18N
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        pregledMenu.add(jMenuItem8);

        jMenuItem9.setText(resourceMap.getString("jMenuItem9.text")); // NOI18N
        jMenuItem9.setName("jMenuItem9"); // NOI18N
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        pregledMenu.add(jMenuItem9);

        jMenuItem10.setText(resourceMap.getString("jMenuItem10.text")); // NOI18N
        jMenuItem10.setName("jMenuItem10"); // NOI18N
        pregledMenu.add(jMenuItem10);

        menuBar.add(pregledMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 417, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // prikazati panel za unos podataka o vozilima
        //getFrame().getContentPane().add(unosVozilaPanel);
        
        showPanel(VOZILA_PANEL);

    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void unosUposlenikaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unosUposlenikaMenuItemActionPerformed
        //getFrame().getContentPane().add(unosUposlenikaPanel);
        showPanel(UPOSLENICI_PANEL);
    }//GEN-LAST:event_unosUposlenikaMenuItemActionPerformed

    private void unosOrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unosOrgActionPerformed
        //getFrame().getContentPane().add(organizacijaPanel);
        showPanel(ORGANIZACIJE_PANEL);
    }//GEN-LAST:event_unosOrgActionPerformed

    private void unosServisaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unosServisaMenuItemActionPerformed
        //getFrame().getContentPane().add(unosServisaPanel);
        showPanel(UNOS_SERVISA_PANEL);
    }//GEN-LAST:event_unosServisaMenuItemActionPerformed

    private void zahtjevZaGOMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zahtjevZaGOMenuItemActionPerformed
        //getFrame().getContentPane().add(podnosenjeZahtjevaGOPanel);
        showPanel(GODISNJI_ODMORI_PANEL);
    }//GEN-LAST:event_zahtjevZaGOMenuItemActionPerformed

    private void zahtjevZaSPMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zahtjevZaSPMenuItemActionPerformed
        //getFrame().getContentPane().add(podnosenjeZahtjevaSPPanel);
        showPanel(SLUZBENA_PUTOVANJA_PANEL);
    }//GEN-LAST:event_zahtjevZaSPMenuItemActionPerformed

    private void zahtjevZaKancMatMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zahtjevZaKancMatMenuItemActionPerformed
        //getFrame().getContentPane().add(podnosenjeZahtjevaKMPanel);
        showPanel(KANCELARIJSKI_MATERIJAL_PANEL);
    }//GEN-LAST:event_zahtjevZaKancMatMenuItemActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        //getFrame().getContentPane().add(pregledOrJedinicaPanel);
        showPanel(PREGLED_OR_JEDINICA_PANEL);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        //getFrame().getContentPane().add(pregledUposlenikaPanel);
        showPanel(PREGLED_UPOSLENIKA_PANEL);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        //getFrame().getContentPane().add(pregledVozilaPanel);
        showPanel(PREGLED_VOZILA_PANEL);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        //getFrame().getContentPane().add(pregledServisaPanel);
        showPanel(PREGLED_SERVISA_PANEL);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        //getFrame().getContentPane().add(pregledZahtjevaGOPanel);
        showPanel(PREGLED_ZAHTJEVAGO_PANEL);
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        //getFrame().getContentPane().add(pregledZahtjevaSPPanel);
        showPanel(PREGLED_ZAHTJEVASP_PANEL);
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String upit = "SELECT u.iduposlenici, p.naziv FROM uposlenici AS u, pozicije AS p "+
        "WHERE u.Pozicije_idPozicije = p.idPozicije AND u.username = ? AND u.password = ?";
        PreparedStatement pupit = null;
        ResultSet r = null;
        try{
            pupit = (PreparedStatement) kon.GetConnection().prepareStatement(upit);
        
            pupit.setString(1, jTextField1.getText());
            String pass = new String(jPasswordField1.getPassword());
            pupit.setString(2, pass);

             r = pupit.executeQuery();
            }
        catch(Exception e){
            Application.getInstance().exit();
        }

        if (r!=null){
            try{
                while (r.next()){
                    logovan = true;
                    username = jTextField1.getText();
                    jTextField1.setText("");
                    jPasswordField1.setText("");
                    idUposlenici = r.getInt(1);
                    pozicija = r.getString(2);

                    LogujSe();
                }
                if (!logovan){
                    JOptionPane.showMessageDialog(this.mainPanel, "Neispravni podaci", "Greska",1,null);
                }
            }
            catch (SQLException ex)
            {
              System.err.println(ex.getMessage());
            }
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        showPanel(PREGLED_ZAHTJEVAGOa_PANEL);
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        showPanel(PREGLED_ZAHTJEVASPa_PANEL);
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void MenuItemOdjavaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemOdjavaActionPerformed
        LogOut();
    }//GEN-LAST:event_MenuItemOdjavaActionPerformed

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        showPanel(PREGLED_ZAHTJEVAKM_PANEL);
    }//GEN-LAST:event_jMenuItem11ActionPerformed
 
    private void showPanel(int panel) {

       mainPanel.setVisible(false);
       for (int i=0; i<paneli.length; i++)
           paneli[i].setVisible(false);

       if (panel ==-1){ //Main panel
           getFrame().getContentPane().add(mainPanel);
           mainPanel.setVisible(true);
       }
       
       else{
           getFrame().getContentPane().add(paneli[panel]);
           
           paneli[panel].setVisible(true);
           paneli[panel].OsvjeziChBOX();
       }
       

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem MenuItemOdjava;
    private javax.swing.JMenu godisnjiMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JMenu kancMatMenu;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu organizacijaMenu;
    private javax.swing.JMenu pregledMenu;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JMenu sluzbenaPutovanjaMenu;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JMenuItem unosOrg;
    private javax.swing.JMenuItem unosServisaMenuItem;
    private javax.swing.JMenuItem unosUposlenikaMenuItem;
    private javax.swing.JMenu uposleniciMenu;
    private javax.swing.JMenu vozilaMenu;
    private javax.swing.JMenuItem zahtjevZaGOMenuItem;
    private javax.swing.JMenuItem zahtjevZaKancMatMenuItem;
    private javax.swing.JMenuItem zahtjevZaSPMenuItem;
    // End of variables declaration//GEN-END:variables

    public final static int MAIN_PANEL = -1;
    public final static int VOZILA_PANEL = 0;
    public final static int ORGANIZACIJE_PANEL = 1;
    public final static int UPOSLENICI_PANEL = 2;
    public final static int SLUZBENA_PUTOVANJA_PANEL = 3;
    public final static int UNOS_SERVISA_PANEL = 4;
    public final static int GODISNJI_ODMORI_PANEL = 5;
    public final static int KANCELARIJSKI_MATERIJAL_PANEL = 6;

    public final static int PREGLED_OR_JEDINICA_PANEL = 7;
    public final static int PREGLED_UPOSLENIKA_PANEL = 8;
    public final static int PREGLED_VOZILA_PANEL = 9;
    public final static int PREGLED_SERVISA_PANEL = 10;
    public final static int PREGLED_ZAHTJEVAGO_PANEL = 11;
    public final static int PREGLED_ZAHTJEVASP_PANEL = 12;
    public final static int PREGLED_ZAHTJEVAKM_PANEL = 15;

    public final static int PREGLED_ZAHTJEVAGOa_PANEL = 13;
    public final static int PREGLED_ZAHTJEVASPa_PANEL = 14;


    // paneli
    UnosVozilaPanel unosVozilaPanel;
    UnosUposlenikaPanel unosUposlenikaPanel;
    UnosOrganizacioneJedinicePanel organizacijaPanel;
    UnosServisaPanel unosServisaPanel;
    PodnosenjeZahtjevaGOPanel podnosenjeZahtjevaGOPanel;
    PodnosenjeZahtjevSPPanel podnosenjeZahtjevaSPPanel;
    PodnosenjeZahtjevaKMPanel podnosenjeZahtjevaKMPanel;

    PregledOrganizacionihJedinicaPanel pregledOrJedinicaPanel;
    PregledUposlenikaPanel pregledUposlenikaPanel;
    PregledVozilaPanel pregledVozilaPanel;
    PregledServisaPanel pregledServisaPanel;
    PregledZahtjevaGOPanel pregledZahtjevaGOPanel;
    PregledZahtjevaSPPanel pregledZahtjevaSPPanel;
    PregledZahtjevaKMPanel pregledZahtjevaKMPanel;

    PregledZahtjevaGOadminPanel pregledZahtjevaGOadminPanel;
    PregledZahtjevaSPadminPanel pregledZahtjevaSPadminPanel;

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private Paneli[] paneli;

    private void kreirajPanele() {
        try{
            unosVozilaPanel = new UnosVozilaPanel(kon);
            unosUposlenikaPanel = new UnosUposlenikaPanel(kon);
            organizacijaPanel = new UnosOrganizacioneJedinicePanel(kon);
            unosServisaPanel = new UnosServisaPanel(kon);
            podnosenjeZahtjevaGOPanel = new PodnosenjeZahtjevaGOPanel(kon);
            podnosenjeZahtjevaSPPanel = new PodnosenjeZahtjevSPPanel(kon);
            podnosenjeZahtjevaKMPanel = new PodnosenjeZahtjevaKMPanel(kon);

            pregledOrJedinicaPanel = new PregledOrganizacionihJedinicaPanel(kon);
            pregledUposlenikaPanel = new PregledUposlenikaPanel(kon);
            pregledVozilaPanel = new PregledVozilaPanel(kon);
            pregledServisaPanel = new PregledServisaPanel(kon);
            pregledZahtjevaGOPanel = new PregledZahtjevaGOPanel(kon);
            pregledZahtjevaSPPanel = new PregledZahtjevaSPPanel(kon);
            pregledZahtjevaKMPanel = new PregledZahtjevaKMPanel(kon);

            pregledZahtjevaGOadminPanel = new PregledZahtjevaGOadminPanel(kon);
            pregledZahtjevaSPadminPanel = new PregledZahtjevaSPadminPanel(kon);

            paneli = new Paneli[] {unosVozilaPanel, organizacijaPanel,
            unosUposlenikaPanel, podnosenjeZahtjevaSPPanel, unosServisaPanel, podnosenjeZahtjevaGOPanel,
            podnosenjeZahtjevaKMPanel, pregledOrJedinicaPanel, pregledUposlenikaPanel,
            pregledVozilaPanel, pregledServisaPanel, pregledZahtjevaGOPanel, pregledZahtjevaSPPanel,
            pregledZahtjevaGOadminPanel,pregledZahtjevaSPadminPanel,pregledZahtjevaKMPanel};
            
            }
            
        catch(Exception e ){
            e.printStackTrace();
        }
    }

    private void LogujSe() {

        MenuItemOdjava.setVisible(true);
        if (pozicija.equals("Manager")){
            organizacijaMenu.setVisible(true);
            uposleniciMenu.setVisible(true);
            vozilaMenu.setVisible(true);
            pregledMenu.setVisible(true);
            mainPanel.setVisible(false);
            getFrame().setTitle("HR aplikacija - " + username + " (ADMIN)");
        }

        else{
            pregledZahtjevaGOPanel.setIDuposlenika(idUposlenici);
            podnosenjeZahtjevaGOPanel.setIDuposlenika(idUposlenici);
            pregledZahtjevaSPPanel.setIDuposlenika(idUposlenici);
            podnosenjeZahtjevaSPPanel.setIDuposlenika(idUposlenici);
            podnosenjeZahtjevaKMPanel.setIDuposlenika(idUposlenici);
            pregledZahtjevaKMPanel.setIDuposlenika(idUposlenici);

            vozilaMenu.setVisible(true);
            jMenuItem3.setVisible(false);
            godisnjiMenu.setVisible(true);
            sluzbenaPutovanjaMenu.setVisible(true);
            kancMatMenu.setVisible(true);
            mainPanel.setVisible(false);

            getFrame().setTitle("HR aplikacija - " + username);
        }
    }

    private void LogOut() {
        getFrame().setTitle("HR aplikacija");
        idUposlenici = -1;
        pozicija = "";
        logovan = false;
        for (int i=1; i<menuBar.getComponentCount()-1; i++){
            menuBar.getComponent(i).setVisible(false);
        }
        MenuItemOdjava.setVisible(false);
        jMenuItem3.setVisible(true);
        showPanel(MAIN_PANEL);
    }

    public int getIDuposlenika(){
        return idUposlenici;
    }
   
}
